home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir27 / calctool.zip / CALCTOOL.PS < prev    next >
Text File  |  1992-09-09  |  6KB  |  272 lines

  1.  
  2. %  These are the NeWS dependent graphics routines used by calctool.
  3. %  They make use of the tnt toolkit distributed with OpenWindows.
  4. %
  5. %  Copyright (c) Rich Burridge - Sun Microsystems, Australia.
  6. %                                All rights reserved.
  7. %
  8. %  @(#)calctool.ps 1.5 89/12/21
  9. %
  10. %  Permission is given to distribute these sources, as long as the
  11. %  copyright messages are not removed, and no monies are exchanged.
  12. %
  13. %  No responsibility is taken for any errors or inaccuracies inherent
  14. %  either to the comments or the code of this program, but if
  15. %  reported to me then an attempt will be made to fix them.
  16. %
  17.  
  18. %  Define a class for the main calctool window. The following events
  19. %  are handled:
  20. %
  21. %  Left mouse button (down and up).
  22. %  Middle mouse button (down and up).
  23. %  Right mouse button (down and up).
  24. %  Keyboard press.
  25. %  Window damage.
  26. %
  27. %  For each of these events, an appropriate tag is sent back to the C code.
  28.  
  29. /KeyClass ClassCanvas []
  30. classbegin
  31.   /PaintCanvas
  32.   {
  33.     CFRAME_REPAINT typedprint
  34.   } def
  35.  
  36.   /MakeInterests
  37.   {
  38.     /MakeInterests super send
  39.     LeftMouseButton   {LEFT_DOWN SendEvent}   /DownTransition self MakeInterest
  40.     MiddleMouseButton {MIDDLE_DOWN SendEvent} /DownTransition self MakeInterest
  41.     LeftMouseButton   {LEFT_UP SendEvent}     /UpTransition   self MakeInterest
  42.     MiddleMouseButton {MIDDLE_UP SendEvent}   /UpTransition   self MakeInterest
  43.     {KbdEvent} Canvas /defaultkeys ClassKeysInterest send
  44.   } def
  45. classend def
  46.  
  47.  
  48. %  Define a class for the memory register window.
  49. %  Handle window damage in the same way as the main calctool window.
  50.  
  51. /RegClass ClassCanvas []
  52. classbegin
  53.   /PaintCanvas
  54.   {
  55.     RFRAME_REPAINT typedprint
  56.   } def
  57. classend def
  58.  
  59.  
  60. %  Clear the whole of either the main calctool canvas or the memory
  61. %  register canvas to a specific color.
  62.  
  63. /PSClearCanvas      % color canvas => -
  64. {
  65.   dup setcanvas
  66.   ColorTable 3 -1 roll get
  67.   /fillcanvas 3 -1 roll send
  68. } def
  69.  
  70.  
  71. %  Close the main calctool window and unmap the memory register window.
  72.  
  73. /PSCloseFrame      % - => -
  74. {
  75.   /flipiconic KFrame send
  76.   /unmap RFrame send
  77. } def
  78.  
  79.  
  80. %  Color a rectangular area in the main calctool window.
  81.  
  82. /PSColorArea    % color x width height y => -
  83. {
  84.   KC setcanvas
  85.   KCHeight exch sub exch dup 3 1 roll sub 3 1 roll rectpath
  86.   ColorTable exch get setcolor
  87.   fill
  88. } def
  89.  
  90.  
  91. %  Draw a line in the main calctool window.
  92.  
  93. /PSDrawLine           % x1 x2 y1 y2 => -
  94. {
  95.   KCHeight exch sub
  96.   exch KCHeight exch sub 3 1 roll
  97.   KC setcanvas
  98.   newpath
  99.     moveto lineto
  100.     0 setgray
  101.   stroke
  102. } def
  103.  
  104.  
  105. %  Draw (map) the memory register window.
  106.  
  107. /PSDrawRegs
  108. {
  109.   /map RFrame send
  110. } def
  111.  
  112.  
  113. %  Load the small, normal and bold fonts used by calctool.
  114.  
  115. /PSInitFonts     % - => -
  116. {
  117.   /SFont /Courier findfont 10 scalefont def
  118.   /NFont /Courier-Bold findfont 14 scalefont def
  119.   /BFont /Courier-Bold findfont 18 scalefont def
  120. } def
  121.  
  122.  
  123. %  Set up the various tags that are passed back to the C code.
  124. %  Note that at present, some of these tags are not used.
  125.  
  126. /PSInitialise   % - => -
  127. {
  128.   /CFRAME_REPAINT  100 def
  129.   /RFRAME_REPAINT  101 def
  130.   /ENTER_WINDOW    102 def
  131.   /EXIT_WINDOW     103 def
  132.   /KEYBOARD        104 def
  133.   /LEFT_DOWN       105 def
  134.   /LEFT_UP         106 def
  135.   /MIDDLE_DOWN     107 def
  136.   /MIDDLE_UP       108 def
  137.   /RIGHT_DOWN      109 def
  138.   /RIGHT_UP        110 def
  139.   /TAKE_FROM_SHELF 111 def
  140.   /PUT_ON_SHELF    112 def
  141. } def
  142.  
  143.  
  144. %  Test if calctool is running on a color framebuffer.
  145.  
  146. /PSIsColor      % - => iscolorscreen
  147. {
  148.   /Color? framebuffer /Color get def
  149.   Color? {1} {0} ifelse typedprint
  150. } def
  151.  
  152.  
  153. %  Load a red green blue triplet into the appropriate entry in the colortable.
  154.  
  155. /PSLoadColor       % index blue green red => -
  156. {
  157.   255 div
  158.   exch 255 div
  159.   3 -1 roll 255 div
  160.   rgbcolor
  161.   ColorTable 3 1 roll put
  162. } def
  163.  
  164.  
  165. %  Create an array big enough for all the colors used by calctool.
  166.  
  167. /PSMakeColorTable  % size => -
  168. {
  169.   /ColorTable exch array def
  170. } def
  171.  
  172.  
  173. /KbdEvent
  174. {
  175.   begin
  176.     Action /DownTransition eq
  177.       {
  178.         KEYBOARD typedprint Name SendEvent
  179.       } if
  180.   end
  181. } def
  182.  
  183.  
  184. /SendEvent
  185. {
  186.   KC setcanvas
  187.   typedprint
  188.   currentcursorlocation KCHeight exch sub exch
  189.   typedprint typedprint
  190. } def
  191.  
  192.  
  193. /PaintIcon 
  194. {
  195.   clippath pathbbox
  196.   scale pop pop
  197.   0 setgray
  198.   false calctoolIcon imagemaskcanvas
  199. } def
  200.  
  201.  
  202. %  Create the main calctool frame and the memory registers property sheet.
  203. %  Set the size of these items, and place the open frame and icon at the
  204. %  correct place.
  205.  
  206. /PSMakeFrames      % wx wy width height ix iy iconic => -
  207. {
  208.   [ /IsIcon /IconY /IconX /KCHeight /KCWidth /KCY /KCX ]
  209.   { exch def } forall
  210.  
  211. %  /ScreenHeight /size framebuffer send exch def pop
  212.   /ScreenHeight 900 def
  213.  
  214.   /KFrame [KeyClass] [/Footer false /Label false]
  215.     framebuffer /new OpenLookBaseFrame send def
  216.   /KC /client KFrame send def
  217.   KCWidth KCHeight /lockminsize KC send 
  218.   calctoolIcon /seticon KFrame send
  219. %  IconX
  220. %  ScreenHeight FrameHeight sub IconY sub
  221. %  42 64 /reshape /Icon /sendsubframe KFrame send
  222.  
  223.   /preferredsize KFrame send /FrameHeight exch def
  224.                              /FrameWidth  exch def
  225.  
  226.   KCX
  227.   ScreenHeight FrameHeight sub KCY sub
  228.   FrameWidth FrameHeight /reshape KFrame send
  229.  
  230.   /RFrame [RegClass] framebuffer /new OpenLookPropertyFrame send def
  231.   /RC /client RFrame send def 
  232.   /RCHeight 200 def
  233.   KCWidth RCHeight /lockminsize RC send
  234.  
  235.   /activate KFrame send
  236.  
  237. % /map IsIcon 1 eq {/Icon /subframes KFrame send get} {KFrame} ifelse send
  238. % IsIcon 1 eq {/close KFrame send} if
  239.  
  240.   /map KFrame send
  241.  
  242.   /activate RFrame send
  243.   /place RFrame send
  244. } def
  245.  
  246.  
  247. %  Place a colored text string in the appropriate font at the given
  248. %  x,y position in either the main calctool window or the memory
  249. %  register window.
  250.  
  251. /PSMakeText    % string x canvasheight y font color canvas => -
  252. {
  253.   setcanvas
  254.   ColorTable exch get setcolor
  255.   setfont
  256.   sub moveto show
  257. } def
  258.  
  259.  
  260. /PSSetCursor   % type => -
  261. {
  262. } def
  263.  
  264.  
  265. %  Depending upon the current setting, either show (map) or remove
  266. %  (unmap) the memory register window.
  267.  
  268. /PSToggleRegCanvas   % state => -
  269. {
  270.   1 eq { /map RFrame send} { /unmap RFrame send} ifelse
  271. } def
  272.